home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / INT_LABE.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  5.0 KB  |  173 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import java.awt.Font;
  5.  
  6. /** 
  7.  * Subclass of label that displays the integer value associated with its
  8.  * value_a part.  Note: set_text() which is inherited from label allows
  9.  * the displayed string to be set to something other than the value of
  10.  * part_a (even if there is a constraint).  Use of this is "a feature",
  11.  * however, is problematical for most uses since any such string will be 
  12.  * wiped out when part_a is next assigned or computed by the constraint 
  13.  * system (which is essentially an unpredictable occurrence).
  14.  *
  15.  * @author Scott Hudson
  16.  */
  17. public class int_label extends label {
  18.  
  19.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  20.  
  21.   /** 
  22.    * Full constructor. 
  23.    * @param int  val the value to display.
  24.    * @param int  w   the width of the resulting object.
  25.    * @param Font f   the font to draw in.
  26.    */
  27.   public int_label(int val, int width, Font f)
  28.     {
  29.       super(Integer.toString(val), width, f);
  30.       _part_a = val;
  31.     }
  32.  
  33.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  34.  
  35.   /** 
  36.    * Constructor with width defaulting to width of initial displayed value. 
  37.    * @param int  val the value to display.
  38.    * @param Font f   the font to draw in.
  39.    */
  40.   public int_label(int val, Font f)
  41.     {
  42.       super(Integer.toString(val), f);
  43.       _part_a = val;
  44.     }
  45.  
  46.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  47.  
  48.   /** 
  49.    * Constructor with default font. 
  50.    * @param int  val the value to display.
  51.    * @param int  w   the width of the resulting object.
  52.    */
  53.   public int_label(int val, int width)
  54.     {
  55.       super(Integer.toString(val), width);
  56.       _part_a = val;
  57.     }
  58.  
  59.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  60.  
  61.   /** 
  62.    * Constructor with width set by initial display and default font. 
  63.    * @param int  val the value to display.
  64.    */
  65.   public int_label(int val)
  66.     {
  67.       super(Integer.toString(val));
  68.       _part_a = val;
  69.     }
  70.  
  71.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  72.  
  73.   /** Constructor defaulting to 0 value with default width and font. */
  74.   public int_label()
  75.     {
  76.       this(0);
  77.     }
  78.  
  79.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  80.  
  81.   /** 
  82.    * Indicate which values (coordinates/sizes) of this object are 
  83.    * intrinsically constrained by the internals of the object.  In this
  84.    * case we need to remove PART_A from the set reported by our
  85.    * superclass.
  86.    *
  87.    * @return int bitset indicating parts of this object that are intrinsically
  88.    *             defined.
  89.    */
  90.   public int intrinsic_constraints()
  91.     {
  92.       return super.intrinsic_constraints() & ~PART_A;
  93.     }
  94.  
  95.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  96.  
  97.   /** Storage for part_a value (which we display). */
  98.   protected int  _part_a = 0;
  99.  
  100.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  101.  
  102.   /** 
  103.    * Return the value of part_a after evaluating any attached constraints. 
  104.    * @return int up-to-date value of part_a.
  105.    */
  106.   public int part_a() 
  107.     { 
  108.       /* evaluate and return the value */
  109.       eval_part_a();
  110.       return _part_a;
  111.     }
  112.  
  113.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  114.  
  115.   /** 
  116.    * Set part_a value directly bypassing the constraint system.  
  117.    * @param int v the new value.
  118.    */
  119.   protected void set_raw_part_a(int v) 
  120.     {
  121.       /* don't do anything unless this is a change */
  122.       if (v != _part_a)
  123.         {
  124.           /* change the value and damage our image */
  125.           _part_a = v;
  126.       super.set_text(Integer.toString(v));
  127.           damage_self();
  128.         }
  129.     }
  130.  
  131.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  132.  
  133.   /** Set part_a of object.  
  134.    * @param int v the new value.
  135.    */
  136.   public void set_part_a(int v) 
  137.     {
  138.       /* if this has a constraint throw an exception */
  139.       if ((active_constraints() & PART_A) != 0)
  140.         throw new sub_arctic_error(
  141.           "Attempt to assign value to constrained part_a");
  142.       
  143.       /* don't do anything unless this is a change */
  144.       if (v != _part_a)
  145.       {
  146.         set_raw_part_a(v);
  147.         mark_part_a_ood();
  148.       }
  149.     }
  150.  
  151.    //had:
  152.    //* @exception cannot_assign if part_a is controlled by a constraint.
  153.  
  154.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  155. }
  156.  
  157. /*=========================== COPYRIGHT NOTICE ===========================
  158.  
  159. This file is part of the subArctic user interface toolkit.
  160.  
  161. Copyright (c) 1996 Scott Hudson and Ian Smith
  162. All rights reserved.
  163.  
  164. The subArctic system is freely available for most uses under the terms
  165. and conditions described in 
  166.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  167. and appearing in full in the lib/interactor.java source file.
  168.  
  169. The current release and additional information about this software can be 
  170. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  171.  
  172. ========================================================================*/
  173.